#ifndef _CHALLENGE_H_
#define _CHALLENGE_H_

#include "mydll.h"
#include "mytypes.h"

class ChallengeImpl;
class Buffer;

class Challenge
{
 public:
  Challenge(const tByte *remote_public_key, tUInt32 remote_public_key_len, const tByte *private_key, tUInt32 private_key_len,const tByte *challenge_key, tUInt32 challenge_key_len);
  ~Challenge();

  /// \brief Generate a new challenge.
  ///
  /// If a challenge has been already generated before, then 
  /// it will be lost and overwritten by the new one.
  bool Generate();

  /// \brief Compare challenge.
  ///
  /// This function does the following tasks sequentially:
  /// \li Check signature of the sender (SUDH)
  /// \li Resolve the current challenge and compare with the given challenge result.
  bool operator !=(const Challenge &challenge) const;

  /// \brief Decode incoming challenge, check signature and resolve the challenge.
  ///
  /// This function does the following tasks sequentially:
  /// \li Decode incoming challenge and make sure the data are coherent
  /// \li Check signature of the sender (GisusDLL)
  /// \li Resolve the challenge and sign it with its own signature.
  bool Resolve();

  /// \brief Sign with DSA the data content of the challenge.
  bool Sign();

  /// \brief Check whether DSA signature is coherent with the data content of the challenge.
  bool Verify();

  /// \brief Return a read only pointer on the internal data buffer.
  ///
  /// Mainly used for the implementation of << operator of Buffer.
  const tByte *Content() const;

  /// \brief Return a read only pointer on the internal data buffer.
  ///
  /// Mainly used for the implementation of >> operator of Buffer.
  tByte *Content();

 private:
  ChallengeImpl *_impl;
};

#endif /* _CHALLENGE_H_ */
